// Package logic
// @Author zhongxc
// @Date 2024/1/17 14:59:00
// @Desc
package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"time"
	"zhongxc.cc/admin-user-api/internal/svc"
	"zhongxc.cc/grpc-common/admin-user/client/menu"
)

type MenuLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuLogic {
	return &MenuLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MenuLogic) GetMenuList(page int64, rows int64, keyword string) (*menu.MenuListPageResponse, error) {
	ctx, cancelFunc := context.WithTimeout(l.ctx, 30000*time.Second)
	defer cancelFunc()

	userInfo := l.svcCtx.GetUserInfo(l.ctx)
	logx.Info(userInfo)

	pageInfo := &menu.PageInfo{
		Page:    page,
		Limit:   rows,
		Keyword: keyword,
	}

	response, err := l.svcCtx.MenuRpc.List(ctx, pageInfo)
	if err != nil {
		logx.Error(err)
		return nil, err
	}
	return response, nil
}
